﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Application.System.Interface;
using WMS.FC.Domain.DataTransferObject.System;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.Repository;
using WMS.FC.Domain.Service.System.Interface;

namespace WMS.FC.Application.System
{
    public class SplitTableService : ServiceBase, ISplitTableService
    {
        protected readonly IInitializeSplitTableService initializeSplitTableService;
        protected readonly IGetSplitTableDataService getSplitTableDataService;

        public SplitTableService(
            ILogger<ServiceBase> logger,
            IOptions<WmsSettings> options,
            IMapper mapper,
            IUnitOfWork unitOfWork,
            IInitializeSplitTableService initializeSplitTableService,
            IGetSplitTableDataService getSplitTableDataService)
            : base(logger, options, mapper, unitOfWork)
        {
            this.initializeSplitTableService = initializeSplitTableService;
            this.getSplitTableDataService = getSplitTableDataService;
        }

        public async Task<ResponseBase> GetSplitTableData(GetPageDataDTO dTO)
        {
            var response = new ResponseBase();
            try
            {
                var result = await getSplitTableDataService.GetSplitTableData(dTO.MenuId, dTO.Query, dTO.Pagination, dTO.Sorter, dTO.UserInfo);
                response = response.TransferResult(result);
            }
            catch (Exception ex)
            {
                return response.Exception(ex);
            }

            return response;
        }

        public async Task<ResponseBase> InitializeSplitTable(RequestBase dTO)
        {
            var response = new ResponseBase();
            try
            {
                var result = await initializeSplitTableService.InitializeSplitTable();
                response = response.TransferResult(result);
            }
            catch (Exception ex)
            {
                return response.Exception(ex);
            }

            return response;
        }
    }
}
